#!/usr/bin/env sh

IP=$(ifconfig | grep -A 1 'eth0 ' | tail -n 1 | awk -F':' '{print $2}' | awk -F' ' '{print $1}')

docker start mysql
docker run -p 8888:8888 --env TWS_CONFIG_SERVER_HOST="$IP" --name tws-config-server -d thoughtworkschool/tws-config-server
sleep 20s

docker run -p 8000:8000 --env TWS_CONFIG_SERVER_HOST="$IP" --name tws-zuul -d thoughtworkschool/tws-zuul
docker run -p 8085:8085 --env TWS_CONFIG_SERVER_HOST="$IP" --name tws-auth-backend -d thoughtworkschool/tws-auth-backend
docker run -p 8080:8080 --env TWS_CONFIG_SERVER_HOST="$IP" --name tws-user-backend -d thoughtworkschool/tws-user-backend
docker run -p 8086:8086 --env TWS_CONFIG_SERVER_HOST="$IP" --name tws-practise-diary-backend -d thoughtworkschool/tws-practise-diary-backend
docker run -p 8081:8081 --env TWS_CONFIG_SERVER_HOST="$IP" --name tws-organization-backend -d thoughtworkschool/tws-organization-backend
docker run -p 8087:8087 --env TWS_CONFIG_SERVER_HOST="$IP" --name tws-notification-backend -d thoughtworkschool/tws-notification-backend
docker run -p 8090:8090 --env TWS_CONFIG_SERVER_HOST="$IP" -v /root/mount/upload:/backend/src/main/resources/static/upload --name tws-course-backend -d thoughtworkschool/tws-course-backend
docker run -p 8093:8093 --env TWS_CONFIG_SERVER_HOST="$IP" --name tws-diff-backend -d thoughtworkschool/tws-diff-backend
docker run -p 8088:8088 --env TWS_CONFIG_SERVER_HOST="$IP" --name tws-quiz-backend -d thoughtworkschool/tws-quiz-backend

cd jenkins
sh start.sh
cd -

cd nginx
#replace host ip to nginx default config
sed -i "s/TWS_CONFIG_SERVER_HOST/$IP/g" default.conf
docker restart nginx

